/* 
 * File:   ResourceManager.h
 * Copyright (C) 2008, 2009
 *		Sergio Padrino Recio (PadrinatoR)
 *		J. Daniel Expósito Polo (HellSpawn666)
 *		kasikiare
 *
 * Created on 8 de septiembre de 2008, 20:33
 *
 * This file is part of BombProject.
 * 
 * BombProject is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
   
 * BombProject is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with BombProject.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _RESOURCEMANAGER_H
#define	_RESOURCEMANAGER_H

#include <SDL/SDL.h>

#include <string>
#include <map>

using namespace std;

/**
 * Represents an entry in the resource maps.
 * @see ResourceMap, ResourceManager
 */
template <class S> struct ResourceEntry{
	S* resource;
	int numReferences;
};

/**
 * Represents two maps to store <b>resource entries</b>.
 * @see ResourceEntry, ResourceManager
 */
template <class T> class ResourceMap {
private:
	map<string, struct ResourceEntry<T>* > resourcesMap;
	map<T*, string> stringsMap;

public:
	struct ResourceEntry<T>* get(T* resource);
	struct ResourceEntry<T>* get(string filename);
	
	void clear();
	void add(string filename, struct ResourceEntry<T>* resource);
	void erase(T* resource);
};

/**
 * This class represents a global resource manager that lets load and store images, sounds, etc.
 * @see ResourceEntry, ResourceMap
 */
class ResourceManager {
protected:
	ResourceMap<SDL_Surface> imagesList;
	//ResourceMap<Mix_Music> temazos_jeBis_meTaleRos_de_Infierno_666;
	ResourceManager();
	~ResourceManager();
public:
	SDL_Surface* loadImage(string filename);
	void unloadImage(SDL_Surface* image);
	
	void unloadAll();
	
	//Singleton Pattern
	static ResourceManager* getInstance();
	static void deleteInstance();

private:
	static ResourceManager* mInstance;
};

#endif	/* _RESOURCEMANAGER_H */

